package pl.edu.mimuw.irs.core.model.analysis.atomic;

import pl.edu.mimuw.irs.core.global.IDManager;
import pl.edu.mimuw.irs.core.model.analysis.exception.InternalAnalysisException;
import pl.edu.mimuw.irs.core.model.analysis.exception.InternalAnalysisException.AnalysisCause;
import pl.edu.mimuw.irs.core.model.design.atomic.DefaultNodeFactory;
import pl.edu.mimuw.irs.core.model.design.net.IRSRequirement;
import pl.edu.mimuw.irs.core.model.design.net.IRSTransition;
import pl.edu.mimuw.irs.core.model.petrinet.IPlace;
import pl.edu.mimuw.irs.core.model.petrinet.Place;
import pl.edu.mimuw.irs.core.model.petrinet.Transition;

public class AnalysisNodeFactory extends DefaultNodeFactory {

	// *** Constructors
	
	public AnalysisNodeFactory(IDManager manager) {
		super(manager);
	}
	
	// *** Methods
	
	@Override
	public IPlace copyPlace(Place place) {
		if (place instanceof IRSRequirement) {
			return new ActivityPlace(getIdManager(),
					getIdManager().getPrefixedNewId(place.getName()), 
					place.getPosition(), place.getTokens(), 
					(IRSRequirement) place);
		} else {
			return super.copyPlace(place);
		}
	}
	
	@Override
	public Transition copyTransition(Transition transition) {
		if (transition instanceof IRSTransition) {
			IRSTransition irsTransition = (IRSTransition) transition; 
			return new AnalysisTransition(getIdManager(),
					getIdManager().getPrefixedNewId(transition.getName()), 
					irsTransition.getChance(), transition.getPosition());
		} else {
			throw new InternalAnalysisException(AnalysisCause.NOT_IRS_TRANSITION, transition);
		}
	}
}
